<?php

namespace App\Admin\Forms\User;

use App\Models\User\WxUser;
use App\Models\User\WxUserStudentCertify;
use App\Models\Voter\WxVoter;
use App\Models\Voter\WxVoterPlayer;
use App\Models\Voter\WxVoterPlayerBallot;
use App\Wen\Utils\UserUtils;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class UserStudentCertifyNoticeForm extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $user_id = $input['user_id'];
        $title = $input['title'];
        $content = $input['content'];

        if(_empty_($title) || _empty_($user_id) || _empty_($content)){
            return $this->response()->error('参数错误');
        }

        $user = WxUser::find($user_id);
        if($user){
            UserUtils::add_user_notice(4011, $user->id, $title, $content,100);
            return $this->response()
                ->success('发送成功.')
                ->refresh();
        }else{
            return $this->response()->error('用户不存在');
        }
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $user_id = $this->payload["user_id"];
        $model = WxUserStudentCertify::find($user_id);
        $this->hidden('user_id')->value($user_id);

        $this->html(function () {
            return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">当你想给该用户发送系统通知时使用</div>';
        }, '');
        $this->text('title', '通知标题')->default('学生认证审核失败');
        $this->textarea('content', '通知内容')->default('您好，您申请的"'.$model->school.'"身份被驳回，可以联系平台客服咨询');
    }
}
